$(function() {
  $('.faq_error').hide();
  $('input.faq-text-input').css({backgroundColor:"#FFFFFF"});
  $('input.faq-text-input').focus(function(){
    $(this).css({backgroundColor:"#FFDDAA"});
  });
  $('input.faq-text-input').blur(function(){
    $(this).css({backgroundColor:"#FFFFFF"});
  });

  $(".faq_button").click(function() {
		// validate and process form
		// first hide any error messages
    $('.faq_error').hide();	
	
	var question = $("#faq_question").val();
	if (question == "" || question.length < 10) {
      $("label#faq_question_error").show();
	  $("#faq_question").addClass('faq-input-error');
	  $("#faq_question").focus();
      return false;
    }
	else if ($("#faq_question").hasClass('faq-input-error'))
	{
		$("#faq_question").removeClass('faq-input-error');
	}

	var name = $("input#faq_name").val();
	if (name == "") {
      $("label#faq_name_error").show();
	  $("input#faq_name").addClass('faq-input-error');
      $("input#faq_name").focus();
      return false;
    }
	else if ($("input#faq_name").hasClass('faq-input-error'))
	{
		$("input#faq_name").removeClass('faq-input-error');
	}

	var email = $("input#faq_email").val();
	if (email == "") {
      $("label#faq_email_error").show();
	  $("input#faq_email").addClass('faq-input-error');
      $("input#faq_email").focus();
      return false;
    }
	else if ($("input#faq_email").hasClass('faq-input-error'))
	{
		$("input#faq_email").removeClass('faq-input-error');
	}





	var telephone = $("input#faq_telephone").val();
	var occupation = $("input#faq_occupation").val();
	var products_id = $("input[name=faq_products_id]").val();

		
	var dataString = 'name='+ name + '&email=' + email + '&telephone=' + telephone + '&occupation=' + occupation + '&question=' + question + '&products_id=' + products_id;
		
		$.ajax({
      type: "POST",
      url: "reviews/bin/process_faq.php",
      data: dataString,
      success: function() {
        $('#faq_form').html("<div id='faq_message'></div>");
        $('#faq_message').html("<h2>Question Submitted!</h2>")
        .append("<p>Your enquiry has been successfully sent to the us. We will get back to you within one business day. You have a great day!</p>")
        .hide()
        .fadeIn(1000, function() {
          $('#faq_message').append("<img id='checkmark' src='reviews/images/check.png' />");
        });
      }
     });
    return false;
	});
});
runOnLoad(function(){
  $("input#name").select().focus();
});
